package com.banshou.jpush.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;

import com.alibaba.fastjson.JSON;

public class JpushUtil
{
    
private static final String AndroidScreen_appKey = "9a2e88b82b0dc4b539f613de";
    
    private static final String AndroidScreen_masterSecret = "a79f5317b7357271905a44f9";
   
  /*  public static void main(String[] args)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> map1 = new HashMap<>();

                map1.put("tradeNo", "201801120001");
                map1.put("adType", "2");
                try {
                    map1.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map1.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map1.put("aDayMax", "20");
                map1.put("adPath", "http://39.104.52.209:82/v1.mp4");
                Map<String, String> map3 = new HashMap<>();
                map3.put("maxTargetAge", "30");
                map3.put("minTargetAge", "20");
                List list = new ArrayList();
                list.add(map3);
                map1.put("ageRange", list);
                map1.put("targetGender", "0");
                map1.put("price", "0.5");
                map1.put("balance", "50");
                map1.put("lowcaseMd5", "6c571c6f88425079ecedb17f82f7e737");
                Map<String, Object> map2 = new HashMap<>();

                map2.put("tradeNo", "201801120002");
                map2.put("adType", "2");
                try {
                    map2.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map2.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map2.put("aDayMax", "40");
                map2.put("adPath", "http://39.104.52.209:82/v2.mp4");
                Map<String, String> map4 = new HashMap<>();
                map4.put("maxTargetAge", "40");
                map4.put("minTargetAge", "30");
                List list2 = new ArrayList();
                list2.add(map4);

                map2.put("ageRange", list2);
                map2.put("targetGender", "1");
                map2.put("price", "1");
                map2.put("balance", "150");
                map2.put("lowcaseMd5", "06b8fe208cc46409f2abf234786c68c5");

                Map<String, Object> map5 = new HashMap<>();

                map5.put("tradeNo", "201801120003");
                map5.put("adType", "2");
                try {
                    map5.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map5.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map5.put("aDayMax", "40");
                map5.put("adPath", "http://39.104.52.209:82/20to25male.mp4");
                Map<String, String> map6 = new HashMap<>();
                map6.put("maxTargetAge", "25");
                map6.put("minTargetAge", "20");
                List list3 = new ArrayList();
                list3.add(map6);

                map5.put("ageRange", list3);
                map5.put("targetGender", "0");
                map5.put("price", "1");
                map5.put("balance", "150");
                map5.put("lowcaseMd5", "dcc15eb0467c6a1019384bdde89ec6f3");
                
                
                
                
                Map<String, Object> map7 = new HashMap<>();

                map7.put("tradeNo", "201801120004");
                map7.put("adType", "2");
                try {
                    map7.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map7.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map7.put("aDayMax", "40");
                map7.put("adPath", "http://39.104.52.209:82/20to30female.mp4");
                Map<String, String> map8 = new HashMap<>();
                map8.put("maxTargetAge", "30");
                map8.put("minTargetAge", "20");
                List list4 = new ArrayList();
                list4.add(map8);

                map7.put("ageRange", list4);
                map7.put("targetGender", "1");
                map7.put("price", "1");
                map7.put("balance", "150");
                map7.put("lowcaseMd5", "cc1193e3f54ceb483705f9f7b83a2ce9");
                
                Map<String, Object> map9 = new HashMap<>();

                map9.put("tradeNo", "201801120005");
                map9.put("adType", "2");
                try {
                    map9.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map9.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map9.put("aDayMax", "40");
                map9.put("adPath", "http://39.104.52.209:82/20to35female.mp4");
                Map<String, String> map10 = new HashMap<>();
                map10.put("maxTargetAge", "35");
                map10.put("minTargetAge", "20");
                List list5 = new ArrayList();
                list5.add(map10);

                map9.put("ageRange", list5);
                map9.put("targetGender", "1");
                map9.put("price", "1");
                map9.put("balance", "150");
                map9.put("lowcaseMd5", "d86aeab3b0d49f2e9774c12e9077f134");
                
                
                
                
                
                Map<String, Object> map11 = new HashMap<>();

                map11.put("tradeNo", "201801120006");
                map11.put("adType", "2");
                try {
                    map11.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map11.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map11.put("aDayMax", "40");
                map11.put("adPath", "http://39.104.52.209:82/35to40male.mp4");
                Map<String, String> map12 = new HashMap<>();
                map12.put("maxTargetAge", "40");
                map12.put("minTargetAge", "35");
                List list6 = new ArrayList();
                list6.add(map12);

                map11.put("ageRange", list6);
                map11.put("targetGender", "0");
                map11.put("price", "1");
                map11.put("balance", "150");
                map11.put("lowcaseMd5", "03955ab9f03d58f456562213357bdce3");
                
                
                
                
                Map<String, Object> map13 = new HashMap<>();

                map13.put("tradeNo", "201801120007");
                map13.put("adType", "2");
                try {
                    map13.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map13.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map13.put("aDayMax", "40");
                map13.put("adPath", "http://39.104.52.209:82/fm1.mp4");
                Map<String, String> map14 = new HashMap<>();
                map14.put("maxTargetAge", "100");
                map14.put("minTargetAge", "1");
                List list7 = new ArrayList();
                list7.add(map14);

                map13.put("ageRange", list7);
                map13.put("targetGender", "2");
                map13.put("price", "1");
                map13.put("balance", "150");
                map13.put("lowcaseMd5", "b5d42be66ced2e820b318cecd2443dc5");
                
                Map<String, Object> map15 = new HashMap<>();

                map15.put("tradeNo", "201801120008");
                map15.put("adType", "2");
                try {
                    map15.put("beginDate",
                            String.valueOf(sdf.parse("2018-01-29").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                try {
                    map15.put("endDate",
                            String.valueOf(sdf.parse("2018-02-25").getTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                map15.put("aDayMax", "40");
                map15.put("adPath", "http://39.104.52.209:82/fm2.mp4");
                Map<String, String> map16 = new HashMap<>();
                map16.put("maxTargetAge", "100");
                map16.put("minTargetAge", "1");
                List list8 = new ArrayList();
                list8.add(map16);

                map15.put("ageRange", list8);
                map15.put("targetGender", "2");
                map15.put("price", "1");
                map15.put("balance", "150");
                map15.put("lowcaseMd5", "bb53319c7a779bcb6f779de3e7e90c05");
                

                List maps = new ArrayList<>();
                maps.add(map1);
                maps.add(map2);
//                maps.add(map5);
//                maps.add(map7);
//                maps.add(map9);
//                maps.add(map11);
//                maps.add(map13);
//                maps.add(map15);
                
                map.put("resultCode", "200");
                map.put("resultMessage","success");
                

                // data.put("ads", maps);
                map.put("data", maps);
                pushToBanzi(map, "17270382adcafe0f");
    }*/
    public  static boolean pushToBanzi(Map<String, Object> contents, String alias){
        
        System.out.println(JSON.toJSONString(contents));
        int statusCode = -1;
        JPushClient client = new JPushClient(AndroidScreen_masterSecret, AndroidScreen_appKey);
        PushPayload payLoad =
            PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.alias(alias))
                .setMessage(Message.content(JSON.toJSONString(contents)))
                .build();
        try
        {
            statusCode = client.sendPush(payLoad).statusCode;
        }
        catch (APIConnectionException | APIRequestException e)
        {
            
            e.printStackTrace();
    }
        return statusCode == 0;
}
}